package com.mdc.controller;

import com.mdc.bean.Product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Mordecai
 * @version 1.0.0
 * @blog https://gitee.com/mordeky/SpringBoot
 *
 */
@Controller
public class ViewController {
    @RequestMapping("/hello")
    public String index1(ModelMap map) {
        System.out.println(">> ViewController.index1() is called!");
        map.addAttribute("hello", "Hello, Thymeleaf!");
        return "index1";
    }

    @RequestMapping(value="/products", produces="text/plain;charset=UTF-8")
    public String index2(ModelMap map) {
//        Locale locale = LocaleContextHolder.getLocale();

        Product product = new Product("watermelon", 15.00);

        List<Product> list = new ArrayList<>();
        list.add(new Product("苹果", 11.00));
        list.add(new Product("香蕉", 12.15));
        list.add(new Product("Peach", 13.14));

        map.addAttribute("product", product);
        map.addAttribute("allProducts", list);

        return "index2";
    }
}